package com.group7.mall.service.impl;

import com.group7.mall.convert.GoodsConverter;
import com.group7.mall.dao.*;
import com.group7.mall.dto.*;
import com.group7.mall.entity.*;
import com.group7.mall.req.BaiduImageRequest;
import com.group7.mall.req.SellerGoodsPageRequest;
import com.group7.mall.resp.SellerGoodsPageResponse;
import com.group7.mall.service.SellerGoodsService;
import com.group7.mall.util.BaiduSimilarImageServerUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.Instant;
import java.util.*;

@Service
public class SellerGoodsServiceImpl implements SellerGoodsService {

    @Resource
    private TbGoodsDao tbGoodsDao;

    @Resource
    private TbGoodsImageDao tbGoodsImageDao;

    @Resource
    private TbGoodsParameterDao tbGoodsParameterDao;

    @Resource
    private TbUserCommentDao tbUserCommentDao;

    @Resource
    private TbSellerDao tbSellerDao;

    @Resource
    private TbGoodsAttributeDao tbGoodsAttributeDao;

    @Resource
    private TbGoodsTypeDao tbGoodsTypeDao;

    @Resource
    private TbGoodsInventoryPriceDao tbGoodsInventoryPriceDao;

    @Resource
    private TbBrowsingHistoryDao tbBrowsingHistoryDao;

    @Override
    public Integer updateUnbanGoodsType(List<GoodsSpecificationsDto> goodsSpecificationsDtoList) {
        // TODO 更新最低价最高价
        Double minPrice = Double.MAX_VALUE;
        Integer goodsId = null;
        for (GoodsSpecificationsDto goodsSpecificationsDto: goodsSpecificationsDtoList) {
            Double x = goodsSpecificationsDto.getPrice();
            TbGoodsInventoryPrice tbGoodsInventoryPrice = tbGoodsInventoryPriceDao.queryById(goodsSpecificationsDto.getCombinationId());
            tbGoodsInventoryPrice.setCostPrice(goodsSpecificationsDto.getCostPrice());
            tbGoodsInventoryPrice.setInventory(goodsSpecificationsDto.getInventory());
            tbGoodsInventoryPrice.setPrice(goodsSpecificationsDto.getPrice());
            tbGoodsInventoryPrice.setPriceFloat(goodsSpecificationsDto.getPrice() - x);
            tbGoodsInventoryPriceDao.update(tbGoodsInventoryPrice);
            goodsId = tbGoodsInventoryPrice.getGoodsId();
            if (minPrice > tbGoodsInventoryPrice.getPrice()) {
                minPrice = tbGoodsInventoryPrice.getPrice();
            }
        }
        TbGoods tbGoods = tbGoodsDao.queryById(goodsId);
        tbGoods.setMinPrice(minPrice);
        tbGoodsDao.update(tbGoods);
        return 1;
    }

    @Override
    public TbGoods queryById(Integer goodsId) {
        return tbGoodsDao.queryOrderGoodsById(goodsId);
    }



    @Override
    public int deleteAllGoodsParameter(Integer goodsId) {
        return tbGoodsParameterDao.deleteByGoodsId(goodsId);
    }

    @Override
    public int deleteAllGoodsType(Integer goodsId) {
        tbGoodsTypeDao.deleteByGoodsId(goodsId);
        tbGoodsAttributeDao.deleteByGoodsId(goodsId);
        tbGoodsInventoryPriceDao.deleteByGoodsId(goodsId);
        return 1;
    }

    @Override
    public int updateAllGoodsInformation(GoodsAddDto goodsAddDto) throws IOException {
        System.out.println(goodsAddDto.getGoodsId() + " 888");
        // 转换后的图片对象
        TbGoodsImage tbGoodsImage = GoodsConverter.INSTANCE.convertGoodsAddDtoToTbGoodsImage(goodsAddDto);
        List<GoodsParameterDto> goodsParameterDtoList = goodsAddDto.getGoodsParameterDtoList();
        tbGoodsParameterDao.deleteByGoodsId(goodsAddDto.getGoodsId());
        TbGoods tbGoods = tbGoodsDao.queryOrderGoodsById(goodsAddDto.getGoodsId());
        // 获取旧的图片对象
        TbGoodsImage tbGoodsImage1 = tbGoodsImageDao.queryById(goodsAddDto.getGoodsId());
        BaiduImageRequest baiduImageRequest = new BaiduImageRequest();
        // 如果旧的图和新的图不相等，就百度云删除
        if (!Objects.equals(tbGoodsImage1.getGoodsMainImage(), tbGoodsImage.getGoodsMainImage())) {
            baiduImageRequest.setImageUrl(tbGoodsImage.getGoodsMainImage());
            BaiduSimilarImageServerUtils.deleteImage(baiduImageRequest);
        }
        // 删除旧的图片对象
        tbGoodsImageDao.deleteById(goodsAddDto.getGoodsId());
        // 计算最低价
        Double minPrice = Double.MAX_VALUE;
        if (goodsAddDto.getGoodsSpecificationsDtoList() != null) {
            for (GoodsSpecificationsDto x:goodsAddDto.getGoodsSpecificationsDtoList()) {
                if (x.getPrice() < minPrice) {
                    minPrice = x.getPrice();
                }
            }
            tbGoods.setMinPrice(minPrice);
        }
        // 更新最新修改的数据
        tbGoods.setUpdatedTime(goodsAddDto.getUpdatedTime());
        tbGoods.setBrand(goodsAddDto.getBrand());
        tbGoods.setGoodsClass(goodsAddDto.getGoodsClass());
        tbGoods.setGoodsInfo(goodsAddDto.getGoodsInfo());
        tbGoods.setGoodsImage(goodsAddDto.getGoodsMainImage());

        // 把参数塞进去表中
        for(GoodsParameterDto x: goodsParameterDtoList) {
            TbGoodsParameter tbGoodsParameter = new TbGoodsParameter();
            tbGoodsParameter.setGoodsId(goodsAddDto.getGoodsId());
            tbGoodsParameter.setParameterKey(x.getKey());
            tbGoodsParameter.setParameterValue(x.getValue());
            tbGoodsParameterDao.insert(tbGoodsParameter);
        }
        // 如果旧的图和新的图不相等，就把最新的放上去
        if (!Objects.equals(tbGoodsImage1.getGoodsMainImage(), tbGoodsImage.getGoodsMainImage())) {
            baiduImageRequest.setImageUrl(tbGoodsImage.getGoodsMainImage());
            baiduImageRequest.setBrief(String.valueOf(tbGoodsImage.getGoodsId()));
            BaiduSimilarImageServerUtils.addImage(baiduImageRequest);
        }
        tbGoodsImageDao.insert(tbGoodsImage);
        // 更新goods
        return tbGoodsDao.update(tbGoods);
    }

    @Override
    public GoodsAddDto addGoodsAttribute(GoodsAddDto goodsAddDto) {
        List<GoodsSpecificationsDto> goodsSpecificationsDtoList = goodsAddDto.getGoodsSpecificationsDtoList();
        GoodsSpecificationsDto goodsSpecificationsDto = goodsSpecificationsDtoList.get(0);
        TbGoodsAttribute tbGoodsAttribute = new TbGoodsAttribute();
        tbGoodsAttribute.setAttributeName(goodsSpecificationsDto.getSpecificationsName1());
        tbGoodsAttribute.setAttributeLevel(1);
        tbGoodsAttribute.setGoodsId(goodsAddDto.getGoodsId());
        tbGoodsAttributeDao.insert(tbGoodsAttribute);
        goodsAddDto.setAttributeId1(tbGoodsAttribute.getAttributeId());
        if (goodsSpecificationsDto.getSpecificationsName2() != null) {
            tbGoodsAttribute.setAttributeName(goodsSpecificationsDto.getSpecificationsName2());
            tbGoodsAttribute.setAttributeLevel(2);
            tbGoodsAttributeDao.insert(tbGoodsAttribute);
            goodsAddDto.setAttributeId2(tbGoodsAttribute.getAttributeId());
        }
        if (goodsSpecificationsDto.getSpecificationsName3() != null) {
            tbGoodsAttribute.setAttributeName(goodsSpecificationsDto.getSpecificationsName3());
            tbGoodsAttribute.setAttributeLevel(3);
            tbGoodsAttributeDao.insert(tbGoodsAttribute);
            goodsAddDto.setAttributeId3(tbGoodsAttribute.getAttributeId());
        }
        return goodsAddDto;
    }

    @Override
    public GoodsAddDto addGoodsParameter(GoodsAddDto goodsAddDto) {
        List<GoodsParameterDto> goodsParameterDtoList = goodsAddDto.getGoodsParameterDtoList();
        for(GoodsParameterDto x: goodsParameterDtoList) {
            TbGoodsParameter tbGoodsParameter = new TbGoodsParameter();
            tbGoodsParameter.setGoodsId(goodsAddDto.getGoodsId());
            tbGoodsParameter.setParameterKey(x.getKey());
            tbGoodsParameter.setParameterValue(x.getValue());
            Instant now = Instant.now();
            long timestamp = now.toEpochMilli();
            tbGoodsParameterDao.insert(tbGoodsParameter);
        }
        return goodsAddDto;
    }

    @Override
    public GoodsAddDto addGoodsType(GoodsAddDto goodsAddDto) {
        Map<String, String> specificationsItemName1Map = new HashMap<>();
        Map<String, String> specificationsItemName2Map = new HashMap<>();
        Map<String, String> specificationsItemName3Map = new HashMap<>();
        List<String> specificationsItemName1List = new ArrayList<>();
        List<String> specificationsItemName2List = new ArrayList<>();
        List<String> specificationsItemName3List = new ArrayList<>();
        List<GoodsSpecificationsDto> goodsSpecificationsDtoList = goodsAddDto.getGoodsSpecificationsDtoList();
        for (GoodsSpecificationsDto x: goodsSpecificationsDtoList) {
            if (specificationsItemName1Map.get(x.getSpecificationsItemName1()) == null && x.getSpecificationsItemName1() != null) {
                specificationsItemName1Map.put(x.getSpecificationsItemName1(), "ok");
                specificationsItemName1List.add(x.getSpecificationsItemName1());
            }
            if (specificationsItemName2Map.get(x.getSpecificationsItemName2()) == null && x.getSpecificationsItemName2() != null) {
                specificationsItemName2Map.put(x.getSpecificationsItemName2(), "ok");
                specificationsItemName2List.add(x.getSpecificationsItemName2());
            }
            if (specificationsItemName3Map.get(x.getSpecificationsItemName3()) == null && x.getSpecificationsItemName3() != null) {
                specificationsItemName3Map.put(x.getSpecificationsItemName3(), "ok");
                specificationsItemName3List.add(x.getSpecificationsItemName3());
            }
        }

        TbGoodsType tbGoodsType = new TbGoodsType();
        tbGoodsType.setGoodsId(goodsAddDto.getGoodsId());

        for(String x: specificationsItemName1List){
            tbGoodsType.setAttributeId(goodsAddDto.getAttributeId1());
            tbGoodsType.setTypeName(x);
            tbGoodsTypeDao.insert(tbGoodsType);
        }

        if (!specificationsItemName2List.isEmpty()) {
            for(String x: specificationsItemName2List){
                tbGoodsType.setAttributeId(goodsAddDto.getAttributeId2());
                tbGoodsType.setTypeName(x);
                tbGoodsTypeDao.insert(tbGoodsType);
            }
        }

        if (!specificationsItemName3List.isEmpty()) {
            for(String x: specificationsItemName3List){
                tbGoodsType.setAttributeId(goodsAddDto.getAttributeId3());
                tbGoodsType.setTypeName(x);
                tbGoodsTypeDao.insert(tbGoodsType);
            }
        }

        return goodsAddDto;
    }

    @Override
    public GoodsAddDto addGoodsInventoryPrice(GoodsAddDto goodsAddDto) {
        TbGoodsAttribute tbGoodsAttribute1 = tbGoodsAttributeDao.queryAttributeLevel1ByGoodsId(goodsAddDto.getGoodsId());
        TbGoodsAttribute tbGoodsAttribute2 = tbGoodsAttributeDao.queryAttributeLevel2ByGoodsId(goodsAddDto.getGoodsId());
        TbGoodsAttribute tbGoodsAttribute3 = tbGoodsAttributeDao.queryAttributeLevel3ByGoodsId(goodsAddDto.getGoodsId());
        List<TbGoodsType> tbGoodsTypeList1 = tbGoodsTypeDao.queryByAttributeId(tbGoodsAttribute1.getAttributeId());
        List<TbGoodsType> tbGoodsTypeList2 = new ArrayList<>();
        List<TbGoodsType> tbGoodsTypeList3 = new ArrayList<>();
        if (tbGoodsAttribute2 != null) {
            tbGoodsTypeList2 = tbGoodsTypeDao.queryByAttributeId(tbGoodsAttribute2.getAttributeId());
        }
        if (tbGoodsAttribute3 != null) {
            tbGoodsTypeList3 = tbGoodsTypeDao.queryByAttributeId(tbGoodsAttribute3.getAttributeId());
        }
        Map<String, Integer> tbGoodsTypeMap1 = new HashMap<>();
        Map<String, Integer> tbGoodsTypeMap2 = new HashMap<>();
        Map<String, Integer> tbGoodsTypeMap3 = new HashMap<>();

        for(TbGoodsType x: tbGoodsTypeList1) {
            tbGoodsTypeMap1.put(x.getTypeName(), x.getTypeId());
        }

        if (!tbGoodsTypeList2.isEmpty()) {
            for(TbGoodsType x: tbGoodsTypeList2) {
                tbGoodsTypeMap2.put(x.getTypeName(), x.getTypeId());
            }
        }

        if (!tbGoodsTypeList3.isEmpty()) {
            for(TbGoodsType x: tbGoodsTypeList3) {
                tbGoodsTypeMap3.put(x.getTypeName(), x.getTypeId());
            }
        }

        Double minPrice = Double.MAX_VALUE;
        TbGoods tbGoods = tbGoodsDao.queryOrderGoodsById(goodsAddDto.getGoodsId());
        List<GoodsSpecificationsDto> goodsSpecificationsDtoList = goodsAddDto.getGoodsSpecificationsDtoList();
        for (GoodsSpecificationsDto x: goodsSpecificationsDtoList) {
            TbGoodsInventoryPrice tbGoodsInventoryPrice = new TbGoodsInventoryPrice();
            tbGoodsInventoryPrice.setGoodsId(goodsAddDto.getGoodsId());
            tbGoodsInventoryPrice.setPriceFloat(0.0);
            tbGoodsInventoryPrice.setPurchaseCount(0);
            tbGoodsInventoryPrice.setTypeId1(tbGoodsTypeMap1.get(x.getSpecificationsItemName1()));
            tbGoodsInventoryPrice.setTypeId2(tbGoodsTypeMap2.get(x.getSpecificationsItemName2()));
            tbGoodsInventoryPrice.setTypeId3(tbGoodsTypeMap3.get(x.getSpecificationsItemName3()));
            tbGoodsInventoryPrice.setInventory(x.getInventory());
            tbGoodsInventoryPrice.setPrice(x.getPrice());
            tbGoodsInventoryPrice.setCostPrice(x.getCostPrice());
            tbGoodsInventoryPrice.setImage(x.getImage());
            // TODO 更新最低价和最高价
            if (minPrice > x.getPrice()) {
                minPrice = x.getPrice();
                tbGoods.setMinPrice(minPrice);
            }
            tbGoodsInventoryPriceDao.insert(tbGoodsInventoryPrice);
        }
        tbGoodsDao.update(tbGoods);
        return goodsAddDto;
    }

    @Override
    public GoodsAddDto addGoodsParameterAndImages(GoodsAddDto goodsAddDto) throws IOException {

        List<GoodsParameterDto> goodsParameterDtoList = goodsAddDto.getGoodsParameterDtoList();

        for(GoodsParameterDto x: goodsParameterDtoList) {
            TbGoodsParameter tbGoodsParameter = new TbGoodsParameter();
            tbGoodsParameter.setGoodsId(goodsAddDto.getGoodsId());
            tbGoodsParameter.setParameterKey(x.getKey());
            tbGoodsParameter.setParameterValue(x.getValue());
            tbGoodsParameterDao.insert(tbGoodsParameter);
        }
        BaiduImageRequest baiduImageRequest = new BaiduImageRequest();
        TbGoodsImage tbGoodsImage = GoodsConverter.INSTANCE.convertGoodsAddDtoToTbGoodsImage(goodsAddDto);
        tbGoodsImageDao.insert(tbGoodsImage);
        baiduImageRequest.setImageUrl(tbGoodsImage.getGoodsMainImage());
        baiduImageRequest.setBrief(String.valueOf(tbGoodsImage.getGoodsId()));
        BaiduSimilarImageServerUtils.addImage(baiduImageRequest);
        return goodsAddDto;
    }

    @Override
    public TbGoods sellerAddGoods(GoodsAddDto goodsAddDto) {
        TbGoods tbGoods = GoodsConverter.INSTANCE.convertGoodsAddDtoToTbGoods(goodsAddDto);
        tbGoods.setIsDeleted(1);
        tbGoods.setClickCount(0);
        tbGoods.setIsNew(0);
        tbGoods.setMinPrice(0.0);
        tbGoods.setIsRecommendation(0);
        tbGoods.setTurnover(0);
        tbGoods.setGoodsImage(goodsAddDto.getGoodsMainImage());
        tbGoods.setCreatedTime(goodsAddDto.getCreatedTime());
        tbGoods.setGoodsImage(goodsAddDto.getGoodsMainImage());
        tbGoodsDao.insert(tbGoods);
        return tbGoods;
    }

    @Override
    public SellerGoodsDetailDto getGoodsImages(SellerGoodsDetailDto sellerGoodsDetailDto) {
        TbGoodsImage tbGoodsImage = tbGoodsImageDao.queryById(sellerGoodsDetailDto.getGoodsId());
        sellerGoodsDetailDto.setGoodsMainImage(tbGoodsImage.getGoodsMainImage());
        sellerGoodsDetailDto.setGoodsMainImage2(tbGoodsImage.getGoodsMainImage2());
        sellerGoodsDetailDto.setGoodsMainImage3(tbGoodsImage.getGoodsMainImage3());
        sellerGoodsDetailDto.setGoodsMainImage4(tbGoodsImage.getGoodsMainImage4());
        sellerGoodsDetailDto.setGoodsMainImage5(tbGoodsImage.getGoodsMainImage5());
        sellerGoodsDetailDto.setGoodsInfoImage1(tbGoodsImage.getGoodsInfoImage1());
        sellerGoodsDetailDto.setGoodsInfoImage2(tbGoodsImage.getGoodsInfoImage2());
        sellerGoodsDetailDto.setGoodsInfoImage3(tbGoodsImage.getGoodsInfoImage3());
        sellerGoodsDetailDto.setGoodsInfoImage4(tbGoodsImage.getGoodsInfoImage4());
        sellerGoodsDetailDto.setGoodsInfoImage5(tbGoodsImage.getGoodsInfoImage5());
        sellerGoodsDetailDto.setGoodsInfoImage6(tbGoodsImage.getGoodsInfoImage6());
        sellerGoodsDetailDto.setGoodsInfoImage7(tbGoodsImage.getGoodsInfoImage7());
        sellerGoodsDetailDto.setGoodsInfoImage8(tbGoodsImage.getGoodsInfoImage8());
        sellerGoodsDetailDto.setGoodsInfoImage9(tbGoodsImage.getGoodsInfoImage9());
        sellerGoodsDetailDto.setGoodsInfoImage10(tbGoodsImage.getGoodsInfoImage10());
        return sellerGoodsDetailDto;
    }

    @Override
    public Integer banGoods(TbGoods tbGoods) throws IOException {
        Integer goodsId = tbGoods.getGoodsId();
        TbGoodsImage tbGoodsImage = tbGoodsImageDao.queryById(goodsId);
        BaiduImageRequest baiduImageRequest = new BaiduImageRequest();
        baiduImageRequest.setImageUrl(tbGoodsImage.getGoodsMainImage());
        BaiduSimilarImageServerUtils.deleteImage(baiduImageRequest);
        return tbGoodsDao.banGoods(tbGoods.getGoodsId());
    }

    @Override
    public Integer unbanGoods(TbGoods tbGoods) throws IOException {
        Integer goodsId = tbGoods.getGoodsId();
        TbGoodsImage tbGoodsImage = tbGoodsImageDao.queryById(goodsId);
        BaiduImageRequest baiduImageRequest = new BaiduImageRequest();
        baiduImageRequest.setImageUrl(tbGoodsImage.getGoodsMainImage());
        baiduImageRequest.setBrief(String.valueOf(tbGoodsImage.getGoodsId()));
        BaiduSimilarImageServerUtils.addImage(baiduImageRequest);
        return tbGoodsDao.unbanGoods(tbGoods.getGoodsId());
    }

    @Override
    public Integer softDeleteGoods(TbGoods tbGoods) {
        return tbGoodsDao.softDeleteGoods(tbGoods.getGoodsId());
    }

    @Override
    public SellerGoodsPageResponse<SellerGoodsPreviewDto> sellerShowGoodsByPage(SellerGoodsPageRequest sellerGoodsPageRequest) {
        sellerGoodsPageRequest.setPageStart((sellerGoodsPageRequest.getPageNo() - 1) * sellerGoodsPageRequest.getPageSize());
        List<TbGoods> tbGoodsList = tbGoodsDao.queryAllByLimit2(sellerGoodsPageRequest);
        SellerGoodsPageResponse<SellerGoodsPreviewDto> sellerGoodsPageResponse = new SellerGoodsPageResponse<>();
        List<SellerGoodsPreviewDto> sellerGoodsPreviewDtoList = new ArrayList<>();

        for (TbGoods x: tbGoodsList) {
            SellerGoodsPreviewDto sellerGoodsPreviewDto = GoodsConverter.INSTANCE.convertTbGoodsToSellerGoodsPreviewDto(x);
            sellerGoodsPreviewDtoList.add(sellerGoodsPreviewDto);
        }
//        List<SellerGoodsPreviewDto> sellerGoodsPreviewDtoList = GoodsConverter.INSTANCE.convertTbGoodsListToSellerGoodsPreviewDtoList(tbGoodsList);
        sellerGoodsPreviewDtoList.forEach(sellerGoodsPreviewDto -> {
            List<TbGoodsInventoryPrice> tbGoodsInventoryPrices = tbGoodsInventoryPriceDao.queryByGoodsId(sellerGoodsPreviewDto.getGoodsId());
            // 获取最大值
            Optional<Double> maxPrice = tbGoodsInventoryPrices.stream()
                    .map(TbGoodsInventoryPrice::getPrice) // 将每个TbGoodsInventoryPrice对象映射到其price字段
                    .max(Double::compareTo); // 获取最大值

            // 获取最小值
            Optional<Double> minPrice = tbGoodsInventoryPrices.stream()
                    .map(TbGoodsInventoryPrice::getPrice) // 将每个TbGoodsInventoryPrice对象映射到其price字段
                    .min(Double::compareTo); // 获取最小值

            maxPrice.ifPresent(sellerGoodsPreviewDto::setMaxPrice);
            minPrice.ifPresent(sellerGoodsPreviewDto::setMinPrice);
            Integer allInventory = 0;
            for(TbGoodsInventoryPrice x: tbGoodsInventoryPrices) {
                allInventory += x.getInventory();
            }
            sellerGoodsPreviewDto.setInventory(allInventory);
        });
        sellerGoodsPageResponse.setPageSize(sellerGoodsPageRequest.getPageSize());
        sellerGoodsPageResponse.setCurrent(sellerGoodsPageRequest.getPageNo());
        sellerGoodsPageResponse.setRecords(sellerGoodsPreviewDtoList);
        sellerGoodsPageResponse.setTotal(tbGoodsDao.countByLimit(sellerGoodsPageRequest));
        return sellerGoodsPageResponse;
    }

    @Override
    public SellerGoodsDetailDto getGoodsSpecificationsDto(SellerGoodsDetailDto sellerGoodsDetailDto) {
        List<TbGoodsAttribute> tbGoodsAttributeList = tbGoodsAttributeDao.queryGoodsAttributeByGoodsId(sellerGoodsDetailDto.getGoodsId());
        List<TbGoodsInventoryPrice> tbGoodsInventoryPriceList = tbGoodsInventoryPriceDao.queryByGoodsId(sellerGoodsDetailDto.getGoodsId());
        List<GoodsSpecificationsDto> goodsSpecificationsDtoList = new ArrayList<>();
        Map<Integer, String> tbGoodsAttributeMap = new HashMap<>();
        Map<Integer, TbGoodsType> goodsTypeMap = new HashMap<>();
        for(TbGoodsAttribute x: tbGoodsAttributeList) {
            tbGoodsAttributeMap.put(x.getAttributeLevel(), x.getAttributeName());
            List<TbGoodsType> tbGoodsTypeList1 = tbGoodsTypeDao.queryByAttributeId(x.getAttributeId());
            for (TbGoodsType y: tbGoodsTypeList1) {
                goodsTypeMap.put(y.getTypeId(), y);
            }
        }
        for(TbGoodsInventoryPrice x: tbGoodsInventoryPriceList) {
            GoodsSpecificationsDto goodsSpecificationsDto = new GoodsSpecificationsDto();
            goodsSpecificationsDto.setSpecificationsName1(tbGoodsAttributeMap.get(1));
            goodsSpecificationsDto.setSpecificationsItemName1(goodsTypeMap.get(x.getTypeId1()).getTypeName());
            if (tbGoodsAttributeMap.get(2) != null && goodsTypeMap.get(x.getTypeId2()).getTypeName() != null) {
                goodsSpecificationsDto.setSpecificationsName2(tbGoodsAttributeMap.get(2));
                goodsSpecificationsDto.setSpecificationsItemName2(goodsTypeMap.get(x.getTypeId2()).getTypeName());
            }
            if (tbGoodsAttributeMap.get(3) != null && goodsTypeMap.get(x.getTypeId3()).getTypeName() != null) {
                goodsSpecificationsDto.setSpecificationsName3(tbGoodsAttributeMap.get(3));
                goodsSpecificationsDto.setSpecificationsItemName3(goodsTypeMap.get(x.getTypeId3()).getTypeName());
            }
            goodsSpecificationsDto.setCombinationId(x.getCombinationId());
            goodsSpecificationsDto.setPrice(x.getPrice());
            goodsSpecificationsDto.setCostPrice(x.getCostPrice());
            goodsSpecificationsDto.setImage(x.getImage());
            goodsSpecificationsDto.setInventory(x.getInventory());
            goodsSpecificationsDto.setTurnover(x.getPurchaseCount());
            goodsSpecificationsDtoList.add(goodsSpecificationsDto);
        }
        sellerGoodsDetailDto.setGoodsSpecificationsDtoList(goodsSpecificationsDtoList);
        return sellerGoodsDetailDto;
    }

    @Override
    public SellerGoodsDetailDto getGoodsParameter(SellerGoodsDetailDto sellerGoodsDetailDto) {
        List<TbGoodsParameter> tbGoodsParameterList = tbGoodsParameterDao.queryListById(sellerGoodsDetailDto.getGoodsId());
        List<GoodsParameterDto> goodsParameterDtoList = new ArrayList<>();
        for(TbGoodsParameter x: tbGoodsParameterList) {
            GoodsParameterDto goodsParameterDto = new GoodsParameterDto();
            goodsParameterDto.setKey(x.getParameterKey());
            goodsParameterDto.setValue(x.getParameterValue());
            goodsParameterDtoList.add(goodsParameterDto);
        }
        sellerGoodsDetailDto.setGoodsParameterDtoList(goodsParameterDtoList);
        return sellerGoodsDetailDto;
    }

}
